package cn.ondraw.ragflow.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import cn.ondraw.common.core.domain.R;
import cn.ondraw.ragflow.pojo.request.ChatCompletionRequest;
import cn.ondraw.ragflow.service.RagFlowChatCompletionService;
import org.springframework.web.bind.annotation.*;

/**
 * 聊天完成控制器
 */
@RestController
@RequestMapping("/v1")
@Slf4j
@RequiredArgsConstructor
public class RagFlowChatCompletionController {

    private final RagFlowChatCompletionService ragFlowChatCompletionService;

    /**
     * 创建聊天完成响应
     *
     * @param chatId  聊天 ID
     * @param request 聊天完成请求对象
     * @return 包含响应结果的 ResponseEntity 对象
     */
    @PostMapping("/chats_openai/{chat_id}/chat/completions")
    public R<Object> createChatCompletion(@PathVariable("chat_id") String chatId, @RequestBody ChatCompletionRequest request) {
        return R.ok(ragFlowChatCompletionService.createChatCompletion(chatId, request));
    }


    /**
     * 创建代理完成响应
     *
     * @param agentId 代理 ID
     * @param request 聊天完成请求对象
     * @return 包含响应结果的 ResponseEntity 对象
     */
    @PostMapping("/agents_openai/{agent_id}/chat/completions")
    public R<Object> createAgentCompletion(@PathVariable("agent_id") String agentId, @RequestBody ChatCompletionRequest request) {
        return R.ok(ragFlowChatCompletionService.createAgentCompletion(agentId, request));
    }
}
